﻿package net.wangit.dev.wizard;

import net.wangit.jdbc.DB;
import net.wangit.util.Checker;

public class ComponentUtil {

	private static final String SQL_UNIT = "select * from UNIT where uid=?";
	private static final String SQL_UNIT_GROUP = "select * from CGROUP where gid=? and t=2 and t=2";
	private static final String SQL_PK = "select * from COLUMN where t=? and pk=1";
	private static final String SQL_COLUMN = "select * from COLUMN where t=? and c=?";

	public ComponentUtil() {
	}

	public static boolean existentUnit(DB db, String unitId) throws Exception {
		return !Checker.isEmpty(db.query(ComponentUtil.SQL_UNIT, unitId, 2));
	}

	public static boolean existentUnitGroup(DB db, String groupId)
			throws Exception {
		return !Checker.isEmpty(db.query(ComponentUtil.SQL_UNIT_GROUP, groupId,
				2));
	}

	public static boolean hasPrimaryKey(DB db, String tableName)
			throws Exception {
		return !Checker.isEmpty(db.query(ComponentUtil.SQL_PK, tableName, 2));
	}

	public static boolean existentColumn(DB db, String tableName,
			String columnName) throws Exception {
		return !Checker.isEmpty(db.query(ComponentUtil.SQL_COLUMN,
				new String[] { tableName, columnName }, new int[] { 2, 2 }));
	}
}
